package com.thrd.basicframework.ui;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;

/**
 * @author: ${唐杰}
 * @date: 2021/4/8
 */
public class AnimentionRelativeLayout extends RelativeLayout {
    public AnimentionRelativeLayout(Context context) {
        this(context,null);
    }

    public AnimentionRelativeLayout(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public AnimentionRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }



//    @Override
//    public void addView(View child) {
//       // setBackgroundResource(R.drawable.text_image_bg);
//        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(getContext().getResources().getDimensionPixelOffset(R.dimen.qb_px_267),getContext().getResources().getDimensionPixelOffset(R.dimen.qb_px_177));
//        lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);//与父容器的上侧对齐
//        lp.topMargin=getContext().getResources().getDimensionPixelOffset(R.dimen.qb_px_111);
//        lp.leftMargin=getContext().getResources().getDimensionPixelOffset(R.dimen.qb_px_40);
//        child.setLayoutParams(lp);
//        animation(child);
//        super.addView(child);
//    }


//    public void animation(View view){
//
//        ObjectAnimator animator=  animationPanningX(view,-getContext().getResources().getDimensionPixelSize(R.dimen.qb_px_307),0);
//        ObjectAnimator animator1=   animationSpin(view,0.5f,1f);
//        AnimatorSet animatorSet=new AnimatorSet();
//        animatorSet.playTogether(animator,animator1);
//        animatorSet.setDuration(2000);
//        animatorSet.start();
//    }


    public RelativeLayout.LayoutParams viewLayoutParams(int w,int h){
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(w,h);
        return lp;
    }


    public AnimatorSet setAnimatorSet(ObjectAnimator... objectAnimators ){
        AnimatorSet mAnimatorSet=new AnimatorSet();
        mAnimatorSet.playTogether(objectAnimators);
        return mAnimatorSet;
    };



    //左右平移动画
    public ObjectAnimator animationPanningX(View view,int start,int stop){
        ObjectAnimator animator12=ObjectAnimator.ofFloat(view,"TranslationX",start,stop);
        return animator12;
    }

    //上下平移动画
    public ObjectAnimator animationPanningY(View view,int startY,int stopY){
        ObjectAnimator animator12=ObjectAnimator.ofFloat(view,"TranslationY",startY,stopY);
        return animator12;
    }
    //缩放X
    public ObjectAnimator animationScaleX(View view,float strat,float stop){
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", strat,stop);
        return scaleX;
    }

    //缩放Y
    public ObjectAnimator animationScaleY(View view,float strat,float stop){
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleY", strat, stop);
        return scaleX;
    }


    //旋转动画
    public ObjectAnimator animationSpin(View view,float spin){
        ObjectAnimator animator12 = ObjectAnimator.ofFloat(view,"rotation",spin);
        return animator12;
    }

    //渐变
    public ObjectAnimator animationGradient(View view,float startAlpha,float stopAlpha){
        ObjectAnimator animator = ObjectAnimator.ofFloat(view, "alpha", startAlpha, stopAlpha);
        return animator;
    }


}
